package com.zisuyi.game.sdk.base

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.weilele.mvvm.utils.activity.invisible
import com.weilele.mvvm.utils.activity.onClick
import com.weilele.mvvm.utils.activity.visible
import com.weilele.mvvm.view.SimpleSwitchView
import com.zisuyi.game.sdk.library.R

class SwitchView : SimpleSwitchView {
    private val loadingTextView by lazy { loadingView?.findViewById<TextView>(R.id.loadingMessageTv) }
    private val otherTextView by lazy { otherView?.findViewById<TextView>(R.id.emptyHintTv) }
    private val retryView by lazy { otherView?.findViewById<TextView>(R.id.emptyHintTv1) }
    private val loadingTextIv by lazy { otherView?.findViewById<ImageView>(R.id.emptyHintIv) }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)


    constructor(context: Context, getContentView: (ViewGroup) -> View) : super(
            context,
            getContentView
    )

    override fun getDefaultLoadingView(context: Context): View {
        return super.getDefaultLoadingView(context)
    }

    override fun getDefaultOtherView(context: Context): View {
        return super.getDefaultOtherView(context)
    }


    override fun showLoadingView(message: String?, isHideContentView: Boolean, isEnableContentView: Boolean) {
        super.showLoadingView(message, isHideContentView, isEnableContentView)
        loadingTextView?.text = message
    }

    override fun showOtherView(message: String?, drawable: Int?, retryText: String?, onSingleClick: ((View) -> Unit)?) {
        super.showOtherView(message, drawable, retryText, onSingleClick)
        otherTextView?.text = message
        if (drawable != null) {
            loadingTextIv?.setImageResource(drawable)
        } else {
            loadingTextIv?.setImageDrawable(null)
        }
        retryView?.text = retryText
        retryView.onClick(onSingleClick)
        if (onSingleClick == null) {
            retryView.invisible()
        } else {
            retryView.visible()
        }
    }
}